#!/bin/sh
#
#  COPYRIGHT 2004, EMULEX CORPORATION
#  3333 Susan Street, Costa Mesa, CA 92626
#  
#  All rights reserved.  This computer program and related documentation
#  is protected by copyright and distributed under licenses restricting
#  its use, copying, distribution and decompilation.  This computer
#  program and its documentation are CONFIDENTIAL and a TRADE SECRET
#  of EMULEX CORPORATION.  The receipt or possession of this program
#  or its documentation does not convey rights to reproduce or disclose
#  its contents, or to manufacture, use, or sell anything that it may
#  describe, in whole or in part, without the specific written consent
#  of EMULEX CORPORATION.  Any reproduction of this program without
#  the express written consent of EMULEX CORPORATION is a violation
#  of the copyright laws and may subject you to criminal prosecution.
# 

#  Kill parent elxhbamgr
ppid=`ps -eaf | grep elxhbamgr | grep -v grep | grep -v start | awk '{ print $2 }' | sort -n | head -1`
if [ ! -z "$ppid" ];then
    kill $ppid > /dev/null 2>&1
fi

#  Kill any zombied elxhbamgr children
for ppid in `ps -eaf | grep elxhbamgr | grep -v grep | grep -v start | awk '{ print $2 }' | sort -n`
do
    kill -9 $ppid > /dev/null 2>&1
done

platform_os=`uname -s`
if [ "$platform_os" = "Linux" ];then
    #  Start the server daemon if module loaded
    lpfcdfc_loaded=`lsmod | awk '{ print $1 }' | grep lpfcdfc`
    if [ ! -z "$lpfcdfc_loaded" ];then
        if [ -f /usr/sbin/hbanyware/elxhbamgr ]; then
            /usr/sbin/hbanyware/elxhbamgr &
        fi
    else
        echo ""
        echo "Not starting hba manager daemon because 'lpfcdfc' driver module not loaded."
        echo "Load lpfcdfc driver module and retry."
    fi
else
    /usr/sbin/hbanyware/elxhbamgr &
fi
